angular.module('Controller')
.controller('QgyActiveParamConfigCtrl',($scope,activeParam,$localStorage,NgTableParams,commonUtil,cryptUtil,wfAlert,commonConstant,$http, $uibModalInstance, items)->
    $scope.type=type=items.type
    $scope.data=data=items.data
    $scope.modalTitle='配置报名字段'
    $scope.activeBasicParams=data.activeBasicParams
    $scope.activeOtherParams=data.activeOtherParams
    $scope.customParamList=data.customParamList
    $scope.chkBox={ids:{},disabled:{},data:{}}
    $scope.pickingType={}
    $scope.activeParamTypeList=commonConstant.activeParamTypeList()
    $scope.activeParamRequiredList=commonConstant.activeParamRequiredList()
    loadData=()->
        _.each data.otherParamList,(item)->
            $scope.chkBox.ids[item.paramKey]=true
#            $scope.chkBox.disabled[item.paramKey]=true
            $scope.chkBox.data[item.paramKey]=item
    loadData()
    $scope.addCustomParam=()->
        keyId=1
        console.log('addCustomParam',$scope.customParamList.length>=8)
        if $scope.customParamList.length>0
            lastTmp=_.max($scope.customParamList,(theCustom)->parseInt(theCustom.paramKey.replace('customParam','')))
            console.log(lastTmp)
            keyId=parseInt(lastTmp.paramKey.replace('customParam',''))+1
        if $scope.customParamList.length<8
            data={
                paramKey:'customParam'+keyId
                paramName:'自定义字段'+keyId
                paramValue:'选项一|选项二'
                paramType:1
                options:false
            }
            $scope.customParamList.push(data)
        else
            wfAlert.toastInfo('自定义字段只能添加8个')
        ''
    $scope.resetOptions=(item)->
        $scope.pickingType[item.paramKey]=true
        setTimeout(->
            $scope.pickingType[item.paramKey]=false
            $scope.$digest()
        ,600)
    $scope.removeCustomParam=(item)->
        $scope.customParamList=_.filter($scope.customParamList,(theCus)->theCus.paramKey!=item.paramKey)
    $scope.confirm = ()->
        otherParamList=[]
        _.each $scope.chkBox.ids,(val,id)->
            if val==true and $scope.chkBox.data[id]!=undefined and $scope.chkBox.disabled[id]!=true
                otherParamList.push $scope.chkBox.data[id]
        console.log(otherParamList)
        data={
            otherParamList:angular.copy(otherParamList)
            customParamList:angular.copy($scope.customParamList)
        }
        $uibModalInstance.close(data)
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')

)